<template>
    <el-dialog
            title="新增条目配置"
            :close-on-press-escape="false"
            :show-close="false"
            :close-on-click-modal="false"
            :visible.sync="dialogVisibleStatus"
            width="40%">

        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="条目" prop="entry">
                <el-input v-model="ruleForm.entry" placeholder="请输入条目"></el-input>
            </el-form-item>

            <el-form-item label="条目名称" prop="entryName">
                <el-input v-model="ruleForm.entryName" placeholder="请输入条目名称"></el-input>
            </el-form-item>

            <el-form-item label="开始时间" required>
                <el-col :span="11">
                    <el-form-item prop="startDate">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.startDate"
                                        style="width: 100%;"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-form-item>

            <el-form-item label="结束时间" required>
                <el-col :span="11">
                    <el-form-item prop="endData">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.endData"
                                        style="width: 100%;"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-form-item>


            <el-form-item label="结算sql" prop="settlement">
                <el-input v-model="ruleForm.settlement" placeholder="请输入结算sql"></el-input>
            </el-form-item>


            <el-form-item label="计划sql" prop="plan">
                <el-input v-model="ruleForm.plan" placeholder="请输入计划sql"></el-input>
            </el-form-item>


            <el-form-item label="关联电厂" prop="relation">
                <el-input v-model="ruleForm.relation" placeholder="请输入关联电厂"></el-input>
            </el-form-item>

            <el-button @click="closeAction">取 消</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
        </el-form>
    </el-dialog>
</template>

<script>
    export default {
        name: 'ModelView',
        props: ['dialogVisible', 'obj'],

        data() {
            return {
                ruleForm: this.obj || {
                    entry: '',
                    entryName: '',
                    startDate: '',
                    endData: '',
                    settlement: '',
                    plan: '',
                    relation: ''
                },
                rules: {
                    entry: [
                        {required: true, message: '请输入条目', trigger: 'blur'}
                    ],
                    entryName: [
                        {required: true, message: '请输入条目名称', trigger: 'blur'}
                    ],

                    startDate: [
                        {required: true, message: '请选择开始时间', trigger: 'change'}
                    ],
                    endData: [
                        {required: true, message: '请选择结束时间', trigger: 'change'}
                    ],

                    settlement: [
                        {required: true, message: '请输入结算sql', trigger: 'blur'}
                    ],
                    plan: [
                        {required: true, message: '请输入计划sql', trigger: 'blur'}
                    ],
                    relation: [
                        {required: true, message: '请输入关联电厂', trigger: 'blur'}
                    ]
                },


                dialogVisibleStatus: this.dialogVisible,
                objData: this.obj
            };
        },

        mounted: function () {
        },

        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid, object) => {
                    if (valid) {
                        console.log(this.ruleForm);
                        this.$emit('closeAction');
                    } else {
                        return false;
                    }
                });
            },

            closeAction() {
                this.$emit('closeAction');
            }
        }
    };
</script>

<style scoped>

</style>